package com.glsc.ngateway.platform.service.itflow.flowstrategy.systemNameApply;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.flowable.dto.FlowCommonTaskDto;
import com.glsc.ngateway.common.api.flowable.dto.param.DoTaskCommentDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.AbstractCreateParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.AbstractFlowSearchParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.AbstractPassParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.system.SystemPassParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.system.SystemRejectParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.system.SystemNameApplyTaskFormDataDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.system.domainDto.FlowFormSystemNameApplyDto;
import com.glsc.ngateway.common.api.flowable.feign.IFeignFlowableService;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import com.glsc.ngateway.common.api.ldap.dto.LdapEhrDeptDto;
import com.glsc.ngateway.common.api.ldap.dto.LdapEhrEmpDto;
import com.glsc.ngateway.common.api.ldap.feign.IFeignLdapService;
import com.glsc.ngateway.common.api.ldap.resp.AppEhrResponse;
import com.glsc.ngateway.common.api.platform.dto.user.PlatformUserDto;
import com.glsc.ngateway.common.api.platform.dto.user.UserLeadersDto;
import com.glsc.ngateway.common.base.converter.platform.FlowFormSystemNameApplyConverter;
import com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow.TOaFlowSyncLog;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.FlowFormSystemNameApply;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.ItDict;
import com.glsc.ngateway.common.base.enums.FlowableResponseSituationStatusEnum;
import com.glsc.ngateway.common.base.enums.OaFlowSyncLogStatusEnum;
import com.glsc.ngateway.common.base.enums.OaFlowSyncMessageDescriptionEnum;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowEnum;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowStatus;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowTaskEnum;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowTaskParamEnum;
import com.glsc.ngateway.common.base.exception.PlatformException;
import com.glsc.ngateway.common.base.repo.mysql.gateway.oaflow.TOaFlowSyncLogRepository;
import com.glsc.ngateway.common.base.repo.mysql.gateway.platform.FlowFormSystemNameApplyRepo;
import com.glsc.ngateway.platform.service.FlowCommonService;
import com.glsc.ngateway.platform.service.RoleService;
import com.glsc.ngateway.platform.service.UserService;
import com.glsc.ngateway.platform.service.it.DictionaryService;
import com.glsc.ngateway.platform.service.itflow.flowstrategy.AbstractItFlowStrategy;
import com.glsc.ngateway.platform.service.itflow.flowstrategy.systemNameApply.taskPostHandler.ISystemNameApplyTaskPostHandlerAudit;
import com.glsc.ngateway.platform.service.itflow.flowstrategy.systemNameApply.taskPostHandler.SNAStepHandlerHelper;
import com.glsc.ngateway.platform.service.system.SystemMainService;
import com.glsc.ngateway.platform.service.system.SystemVendorInfoService;
import lombok.Getter;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

/**
 * 系统名称申请流程策略类
 *
 * @author xuchang
 */
@Getter
@Component
public class SystemNameApplyFlowStrategy extends AbstractItFlowStrategy<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto> {

    Logger logger = LoggerFactory.getLogger(SystemNameApplyFlowStrategy.class);

    public static final String NULL_STR = "null";

    @Resource
    private IFeignLdapService iFeignLdapService;

    @Resource
    private IFeignFlowableService iFeignFlowableService;

    @Autowired
    private FlowFormSystemNameApplyRepo flowFormSystemNameApplyRepo;

    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;

    private Map<String, ISystemNameApplyTaskPostHandlerAudit> taskPostHandlerMap;

    @Autowired
    public void setTaskPostHandlerMap(List<ISystemNameApplyTaskPostHandlerAudit> taskPostHandlerList) {
        this.taskPostHandlerMap = taskPostHandlerList.stream()
                .collect(Collectors.toMap(ISystemNameApplyTaskPostHandlerAudit::getTaskDefinitionKey, handler -> handler));
    }

    @Autowired
    private FlowCommonService flowCommonService;

    @Autowired
    private SystemMainService systemMainService;

    @Autowired
    private SNAStepHandlerHelper handlerHelper;

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private SystemVendorInfoService vendorInfoService;

    @Autowired
    private TOaFlowSyncLogRepository logRepository;

    @Override
    public ITFlowEnum getFlowEnum() {
        return ITFlowEnum.SYSTEM_NAME_APPLY;
    }

    /**
     * 流程节点，发起时动态指定节点处理人
     */
    @Override
    protected Map<String, List<String>> initDefaultTaskUserGroup(PlatformUserDto creator) throws PlatformException {
        Map<String, List<String>> taskAssignee = new HashMap<>(16);
        //1、发起人
        taskAssignee.put(ITFlowTaskParamEnum.SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK_ASSIGNMENTS.getName(), Arrays.asList(creator.getUsername()));
        UserLeadersDto userLeadersDto = userService.getDirectLeaderAndPrimaryDepartmentLeader(creator);
        //2、直属上级
        if (CollectionUtils.isEmpty(userLeadersDto.getDirectLeaders())) {
            throw PlatformException.error("未找到直属上级", false, false);
        }
        taskAssignee.put(ITFlowTaskParamEnum.SYSTEM_NAME_APPLY_FLOW_LEADER_TASK_ASSIGNMENTS.getName(), userLeadersDto.getDirectLeaders());
        //3、部门领导
        if (CollectionUtils.isEmpty(userLeadersDto.getLevelOneDepLeaders())) {
            throw PlatformException.error("未找到部门领导", false, false);
        }
        taskAssignee.put(ITFlowTaskParamEnum.SYSTEM_NAME_APPLY_FLOW_DEPARTMENT_SUPER_TASK_ASSIGNMENTS.getName(), userLeadersDto.getLevelOneDepLeaders());
        return taskAssignee;
    }

    /**
     * 流程节点其他变量
     */
    @Override
    protected Map<String, String> initDefaultTaskConditionalVar(Map<String, String> taskAssignee, PlatformUserDto createUser) {
        return new HashMap<>(0);
    }

    /**
     * 流程创建后置处理
     */
    @Override
    protected void createAfterHandle(AbstractCreateParamDto<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto> param, String operator) {
        FlowFormSystemNameApplyDto formMainData = param.getFlowableFormData().getFormMainData();
        ResponseSituationDto processInfo = flowCommonService.getProcessInfo(param.getProcessId());
        //保存草稿时不需要通知
        if (StrUtil.isBlank(param.getCreateToTaskDefinitionKey())
                || !param.getCreateToTaskDefinitionKey().equals(FlowCommonTaskDto.BEGIN_TASK)) {
            //发送邮件通知下一节点审批
            handlerHelper.notify(processInfo, formMainData.getProcessTitle(), formMainData.getFlowCreateOperatorName(), formMainData.getOpName());
        }
    }

    @Override
    public SystemNameApplyTaskFormDataDto saveOrUpdateForm(SystemNameApplyTaskFormDataDto flowableForm) {
        if (StringUtils.isNotBlank(flowableForm.getProcessId())) {
            flowableForm.getFormMainData().setProcessId(flowableForm.getProcessId());
        }
        FlowFormSystemNameApply oldData = flowFormSystemNameApplyRepo.findByProcessId(flowableForm.getFormMainData().getProcessId());
        if (Objects.nonNull(oldData)) {
            flowableForm.getFormMainData().setId(oldData.getId());
        }
        FlowFormSystemNameApply applyData = FlowFormSystemNameApplyConverter.dto2Do(flowableForm.getFormMainData());
        FlowFormSystemNameApply save = flowFormSystemNameApplyRepo.save(applyData);
        return flowableForm;
    }

    @Override
    public SystemNameApplyTaskFormDataDto findFormByProcessId(String processId) {
        //主表信息
        SystemNameApplyTaskFormDataDto formDataDto = new SystemNameApplyTaskFormDataDto();
        FlowFormSystemNameApply systemNameApply = flowFormSystemNameApplyRepo.findByProcessId(processId);
        FlowFormSystemNameApplyDto systemNameApplyDto = null;
        if (Objects.isNull(systemNameApply)) {
            systemNameApplyDto = new FlowFormSystemNameApplyDto();
        } else {
            systemNameApplyDto = FlowFormSystemNameApplyConverter.do2Dto(systemNameApply);
            Map<String, String> ldapDeptMap = iFeignLdapService.getAllDept().getData().stream().collect(Collectors.toMap(d -> String.valueOf(d.getDepid()), LdapEhrDeptDto::getDtitle));
            //支持H5
            //转换部门相关
            systemNameApplyDto.setBusinessDepartmentName(CollectionUtil.isEmpty(systemNameApplyDto.getBusinessDepartment()) ? null
                    : systemNameApplyDto.getBusinessDepartment().stream().map(ldapDeptMap::get).collect(Collectors.joining(",")));
            systemNameApplyDto.setBelongDeptName(Strings.isBlank(systemNameApplyDto.getBelongDeptId()) ? null
                    : ldapDeptMap.get(systemNameApplyDto.getBelongDeptId()));
            systemNameApplyDto.setOpGroupName(CollectionUtil.isEmpty(systemNameApplyDto.getOpGroupId()) ? null
                    : systemNameApplyDto.getOpGroupId().stream().map(ldapDeptMap::get).collect(Collectors.joining(",")));
            //转换人相关
            Map<String, String> ldapEmpMap = iFeignLdapService.getAllEmps().getData().stream().collect(Collectors.toMap(LdapEhrEmpDto::getBadge, LdapEhrEmpDto::getName));
            systemNameApplyDto.setMemberManagerName(CollectionUtil.isEmpty(systemNameApplyDto.getMemberManager()) ? null
                    :systemNameApplyDto.getMemberManager().stream().map(ldapEmpMap::get).collect(Collectors.joining(",")));
            systemNameApplyDto.setSystemManagerName(CollectionUtil.isEmpty(systemNameApplyDto.getSystemManager()) ? null
                    :systemNameApplyDto.getSystemManager().stream().map(ldapEmpMap::get).collect(Collectors.joining(",")));
            systemNameApplyDto.setOpsManagerName(CollectionUtil.isEmpty(systemNameApplyDto.getOpsManager()) ? null
                    :systemNameApplyDto.getOpsManager().stream().map(ldapEmpMap::get).collect(Collectors.joining(",")));
        }
        formDataDto.setFormMainData(systemNameApplyDto);
        return formDataDto;
    }

    @Override
    public List<String> pageProcessId(AbstractFlowSearchParamDto param, Pageable pageable) {
        return flowFormSystemNameApplyRepo.findAll(
                        (Specification<FlowFormSystemNameApply>) (root, query, builder) -> {
                            List<Predicate> predicateList = new ArrayList<>();
                            if (!io.jsonwebtoken.lang.Collections.isEmpty(param.getAdminList())) {
                                predicateList.add(builder.in(root.get("flowCreateOperatorName")).value(param.getAdminList()));
                            }
                            if (StringUtils.isNotBlank(param.getTitle())) {
                                predicateList.add(builder.equal(root.get("flowTitle"), param.getTitle()));
                            }
                            if (Objects.nonNull(param.getBeginDateLocalDate())) {
                                predicateList.add(builder.greaterThanOrEqualTo(root.get("flowApplyTime"), param.getBeginDateLocalDate()));
                            }
                            if (Objects.nonNull(param.getEndDateLocalDate())) {
                                predicateList.add(builder.lessThanOrEqualTo(root.get("flowApplyTime"), param.getEndDateLocalDate()));
                            }
                            if (Objects.nonNull(param.getHasProcessEnd())) {
                                predicateList.add(builder.equal(root.get("isClose"), param.getHasProcessEnd()));
                            }
                            return builder.and(predicateList.toArray(new Predicate[0]));
                        }, pageable)
                .getContent()
                .stream()
                .map(FlowFormSystemNameApply::getProcessId)
                .collect(Collectors.toList());
    }

    @Override
    protected <A extends AbstractCreateParamDto<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto>> void checkDataBeforeCreateFlow(A taskDto) throws PlatformException {
        if (Objects.isNull(taskDto) || Objects.isNull(taskDto.getFlowableFormData()) || Objects.isNull(taskDto.getFlowableFormData().getFormMainData())) {
            throw PlatformException.error("数据为空", true, false);
        }
        checkData(taskDto.getFlowableFormData().getFormMainData());
    }

    @Override
    protected <A extends AbstractPassParamDto<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto>> void checkDataBeforePassTask(A passDto) throws PlatformException {
        if (Objects.isNull(passDto) || Objects.isNull(passDto.getFlowableFormData()) || Objects.isNull(passDto.getFlowableFormData().getFormMainData())) {
            throw PlatformException.error("数据为空", true, false);
        }
        //被退回到初始节点重新提交后，仍然要检查一次
        if (passDto.getTaskDefinitionKey().equals(ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK.getTaskKey())) {
            checkData(passDto.getFlowableFormData().getFormMainData());
        }
    }

    private void checkData(FlowFormSystemNameApplyDto mainData) {
        if (systemMainService.countByOpName(mainData.getOpName()) > 0) {
            throw PlatformException.error(String.format("已存在【%s】系统", mainData.getOpName()), false, false);
        }
        List<FlowFormSystemNameApply> existList = flowFormSystemNameApplyRepo.findAllByOpNameAndIdNotAndStatusNot(mainData.getOpName(), mainData.getId(), ITFlowStatus.UNUSUAL.getCode());
        if (CollectionUtil.isNotEmpty(existList)) {
            //是否有非强制终止的流程
            AtomicBoolean hasUnusual = new AtomicBoolean(false);
            //再去查flowable，是否被强制取消
            existList.forEach(e -> {
                ResponseSituationDto processInfo = flowCommonService.getProcessInfo(e.getProcessId());
                if (Objects.nonNull(processInfo) && FlowableResponseSituationStatusEnum.UNUSUAL.getCode().equals(processInfo.getStatus())) {
                    e.setStatus(ITFlowStatus.UNUSUAL.getCode());
                    flowFormSystemNameApplyRepo.save(e);
                } else {
                    hasUnusual.set(true);
                }
            });
            if (hasUnusual.get()) {
                throw PlatformException.error(String.format("已有流程申请系统名称为[\"%s\"]，请重新命名", mainData.getOpName()), false, false);
            }
        }
//        if (CollectionUtils.isEmpty(mainData.getBusinessDepartment()) || mainData.getBusinessDepartment().stream().anyMatch(NULL_STR::equals)) {
//            throw PlatformException.error("业务部门不能为空");
//        }
//        if (CollectionUtils.isEmpty(mainData.getOpGroupId()) || mainData.getOpGroupId().stream().anyMatch(NULL_STR::equals)) {
//            throw PlatformException.error("隶属团队不能为空");
//        }
        if (CollectionUtils.isEmpty(mainData.getMemberManager()) || mainData.getMemberManager().stream().anyMatch(NULL_STR::equals)) {
            throw PlatformException.error("项目经理不能为空");
        }
        if (CollectionUtils.isEmpty(mainData.getSystemManager()) || mainData.getSystemManager().stream().anyMatch(NULL_STR::equals)) {
            throw PlatformException.error("系统管理员不能为空");
        }
        if (CollectionUtils.isEmpty(mainData.getOpsManager()) || mainData.getOpsManager().stream().anyMatch(NULL_STR::equals)) {
            throw PlatformException.error("运维管理员不能为空");
        }
    }

    @Override
    protected Map<String, ISystemNameApplyTaskPostHandlerAudit> getTaskPassMap() {
        return taskPostHandlerMap;
    }

    @Override
    protected Map<String, ISystemNameApplyTaskPostHandlerAudit> getTaskRejectMap() {
        return taskPostHandlerMap;
    }

    /**
     * 生成审批要素str，供同步oa使用
     */
    @Override
    public String toSpys(SystemNameApplyTaskFormDataDto formData) {
        StringBuffer sb = new StringBuffer();
        ItDict dict = null;
        FlowFormSystemNameApplyDto formMainData = formData.getFormMainData();
        if (Strings.isNotBlank(formMainData.getSystemClassNo())) {
            sb.append("系统编号:").append(formMainData.getSystemClassNo()).append("<br/>");
        }
        sb.append("系统名称:").append(formMainData.getOpName()).append("<br/>");
        if (Strings.isNotBlank(formMainData.getOpBuild())) {
            dict = dictionaryService.findByDictEntryAndDictSubentry("system_build_type", formMainData.getOpBuild());
            sb.append("建设方式:").append(dict.getDictValue()).append("<br/>");
        }
        if (Strings.isNotBlank(formMainData.getMainClass())) {
            dict = dictionaryService.findByDictEntryAndDictSubentry("system_main_class", formMainData.getMainClass());
            sb.append("系统大类:").append(dict.getDictValue()).append("<br/>");
            dict = dictionaryService.findByDictEntryAndDictSubentry("system_second_class_" + dict.getDictSubentry(), formMainData.getSystemClass());
            sb.append("系统类别:").append(dict.getDictValue()).append("<br/>");
        }
        if (Strings.isNotBlank(formMainData.getSystemImportance())) {
            dict = dictionaryService.findByDictEntryAndDictSubentry("system_importance", formMainData.getSystemImportance());
            sb.append("系统重要性:").append(dict.getDictValue()).append("<br/>");
        }
        //获取所有部门
        AppEhrResponse<List<LdapEhrDeptDto>> depts = iFeignLdapService.getAllDept();
        Map<String, String> depMap = (Objects.isNull(depts) || CollectionUtil.isEmpty(depts.getData())) ? Collections.EMPTY_MAP :
                depts.getData().stream().collect(Collectors.toMap(d -> String.valueOf(d.getDepid()), LdapEhrDeptDto::getDtitle));
        if (CollectionUtil.isNotEmpty(formMainData.getBusinessDepartment())) {
            sb.append("多个业务对口部门:")
                    .append(formMainData.getBusinessDepartment()
                            .stream()
                            .map(d -> Optional.ofNullable(depMap.get(d)).orElseThrow(() ->
                                    PlatformException.error(String.format("同步oa流程异常：未找到业务对口部门：id-%s，depId-%s", formMainData.getId(), d))))
                            .collect(Collectors.joining(",")))
                    .append("<br/>");
        }
        if (Strings.isNotBlank(formMainData.getBelongDeptId())) {
            sb.append("归口管理部门:")
                    .append(Optional.ofNullable(depMap.get(formMainData.getBelongDeptId())).orElseThrow(() ->
                            PlatformException.error(String.format("同步oa流程异常：未找到归口管理部门：id-%s，depId-%s", formMainData.getId(), formMainData.getBelongDeptId()))))
                    .append("<br/>");
        }
        if (CollectionUtil.isNotEmpty(formMainData.getOpGroupId())) {
            sb.append("隶属团队:")
                    .append(formMainData.getOpGroupId().stream()
                            .map(g -> Optional.ofNullable(depMap.get(g)).orElseThrow(() ->
                                    PlatformException.error(String.format("同步oa流程异常：未找到隶属团队：id-%s，depId-%s", formMainData.getId(), formMainData.getOpGroupId()))))
                            .collect(Collectors.joining(","))
                    )
                    .append("<br/>");
        }
        if (CollectionUtil.isNotEmpty(formMainData.getMemberManager())) {
            AppEhrResponse<List<LdapEhrEmpDto>> res = iFeignLdapService.getEmpsByAccounts(formMainData.getMemberManager().stream().distinct().collect(Collectors.toList()));
            List<LdapEhrEmpDto> users = res.getData();
            if (CollectionUtil.isEmpty(users) || users.size() != formMainData.getMemberManager().size()) {
                throw PlatformException.error(String.format("同步oa流程异常：未找到项目经理：id-%s，depId-%s", formMainData.getId(), formMainData.getMemberManager()));
            }
            String nameStr = users.stream().map(LdapEhrEmpDto::getName).collect(Collectors.joining(","));
            sb.append("系统管理员:").append(nameStr).append("<br/>");
        }
        if (Objects.nonNull(formMainData.getOpSupport())) {
            sb.append("供应商:")
                    .append(vendorInfoService.findById(formMainData.getOpSupport()).orElseThrow(() ->
                            PlatformException.error(String.format("同步oa流程异常：未找到供应商：id-%s", formMainData.getOpSupport()))).getVendorName())
                    .append("<br/>");
        }
        if (Strings.isNotBlank(formMainData.getSystemSummary())) {
            sb.append("系统功能描述:").append(Strings.isNotBlank(formMainData.getSystemSummary()) ? formMainData.getSystemSummary() : "无").append("<br/>");
        }
        return sb.toString();
    }

    /**
     * 从oa侧同步流程
     */
    @Override
    public void syncFromOaFlow(TOaFlowSyncLog log, String description) throws Exception {
        OaFlowSyncMessageDescriptionEnum desc = OaFlowSyncMessageDescriptionEnum.valuesOf(description)
                .orElseThrow(() -> PlatformException.error("无法从oa同步，message.desc:" + description));
        SystemNameApplyTaskFormDataDto formData = findFormByProcessId(log.getProcessId());
        //目前oa侧是单节点流程，会受到两条消息，第二条是流程结束，不需要处理
        if (desc.isEnd()) {

        } else if (desc.isPass()) {
            //通过
            SystemPassParamDto<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto> passParam = new SystemPassParamDto<>();
            passParam.setProcessId(log.getProcessId());
            passParam.setTaskId(log.getTaskId());
            passParam.setCommentDto(DoTaskCommentDto.builder().fullMessage("【oa端审批通过】").build());
            passParam.setProcessDefinitionKey(log.getProcessDefKey());
            passParam.setTaskDefinitionKey(log.getTaskDefKey());
            passParam.setProcessTitle(formData.getProcessTitle());
            passParam.setFlowableFormData(formData);
            taskAuditPass(passParam, log.getApproved(), () -> {
                logRepository.updateStatusAndRequestId(log.getWorkflowId(), log.getTaskId(), log.getRequestId(), OaFlowSyncLogStatusEnum.END_OA.getCode());
                auditPassAfterHandle(passParam, log.getApproved());
            });
        } else if (desc.isReject()) {
            //拒绝，跳到上一步
            SystemRejectParamDto rejectParam = new SystemRejectParamDto();
            rejectParam.setProcessId(log.getProcessId());
            rejectParam.setTaskId(log.getTaskId());
            rejectParam.setProcessDefinitionKey(log.getProcessDefKey());
            rejectParam.setTaskDefinitionKey(log.getTaskDefKey());
            rejectParam.setProcessTitle(formData.getProcessTitle());
            //回退至上一步
            ITFlowTaskEnum task = ITFlowEnum.findTask(log.getProcessDefKey(), log.getTaskDefKey());
            if (Objects.isNull(task.getPrevTask())) {
                throw PlatformException.error(String.format("当前无可回退节点:%s, %s", log.getProcessDefKey(), log.getTaskDefKey()));
            }
            rejectParam.setTargetTask(task.getPrevTask().getTaskKey());
            rejectParam.setCommentDto(DoTaskCommentDto.builder().fullMessage("【oa端审批驳回】").build());
//            reject(rejectParam, log.getApproved(), () -> {
//                logRepository.updateStatusAndRequestId(log.getWorkflowId(), log.getTaskId(), log.getRequestId(), OaFlowSyncLogStatusEnum.END_OA.getCode());
//                auditRejectAfterHandle(rejectParam, log.getApproved());
//            });
        }
    }
}
